package cate.game.activity.godtree;

import cate.common.table.activity.godtree.row.MonsterConfigRow;
import cate.common.table.d.GDFight;
import cate.common.table.d.GDOperation;
import cate.game.activity.godtree.msg.GodTreeChallengeResultResp;
import cate.game.play.proce.play.PlayPO;
import cate.game.play.vo.PlayReportVO;
import cate.game.res.MixRes;
import cate.game.role.Role;
import cate.game.role.farm.AbstractFarmFTC;

import java.util.ArrayList;
import java.util.List;

public class GodTreeFTC extends AbstractFarmFTC<GodTreeActivity> {
    /**
     * 当前挑战关卡的模板
     */
    private int pos;
    private final MonsterConfigRow tpl;

    public GodTreeFTC(Role role, int funcId, MonsterConfigRow tpl,int pos) {
        this.funcId = funcId;
        this.tpl = tpl;
        this.pos = pos;
        setup(role);
    }

    @Override
    protected GodTreeActivity po(Role role) {
        return role.getActivity().getEnableActivitySingle(funcId);
    }

    @Override
    public void handleResult(Role role, PlayPO play) {
        super.handleResult(role, play);
        boolean win = play.winner == GDFight.Team.A;
        //是否还要继续挑战
        GodTreeActivity godTreeActivity = po(role);
        if (godTreeActivity == null) {
            return;
        }
        //之前的战报
        List<PlayReportVO> reports = new ArrayList<>();
        GodTreeChallengeResultResp resultResp = new GodTreeChallengeResultResp();
        reports.add(new PlayReportVO(play));
        //赢了就发奖励
        if (win) {
            MixRes reward = new MixRes(tpl.reward);
            resultResp.reward = reward;
            reward.add(role, true, GDOperation.GOD_TREE_FIGHT, tpl.id);
            po(role).killAdd(pos);
            po(role).tryLevelUp(tpl);
        }
        resultResp.funcId = funcId;
        resultResp.win = win;
        resultResp.reports = reports;
        role.sendNow(resultResp);
    }
}
